package com.lyy.system.controller;

import com.lyy.Vo.ProductCategoryTreeNodeVO;
import com.lyy.Vo.UserKeyWord;
import com.lyy.aspect.ControllerEndpoint;
import com.lyy.response.Result;
import com.lyy.system.entity.Product;
import com.lyy.system.entity.ProductCategory;
import com.lyy.system.service.ProductCategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/productCategory")
@Api(value = "业务管理模块",tags = "物资类别接口")
public class ProductCategoryController {

    @Autowired
    private ProductCategoryService productCategoryService;

    @PostMapping("/findProductCategoryList")
    @ApiOperation(value = "物资类别列表",notes = "物资类别列表")
    public Result findProductCategoryList(@RequestBody UserKeyWord userKeyWord){
        List<ProductCategoryTreeNodeVO> productCategoryTreeNodeVOList =productCategoryService.findProductCategoryList(userKeyWord);
        return Result.ok().data("productCategoryList",productCategoryTreeNodeVOList);
    }

    @ControllerEndpoint(exceptionMessage = "添加物资类别失败", operation = "添加物资类别")
    @ApiOperation(value = "添加物资类别",notes = "添加物资类别信息")
    @PostMapping("/addProductCategory")
    public Result addProductCategory(@RequestBody ProductCategory productCategory){
        productCategoryService.addProductCategory(productCategory);
        return Result.ok();
    }

    @ControllerEndpoint(exceptionMessage = "删除物资类别失败", operation = "删除物资类别")
    @ApiOperation(value = "删除物资类别",notes = "删除物资类别信息")
    @DeleteMapping("/deleteProductCategory")
    public Result deleteProductCategory(Long id){
        productCategoryService.deleteProductCategory(id);
        return Result.ok();
    }

    @ControllerEndpoint(exceptionMessage = "更新物资类别失败", operation = "更新物资类别")
    @ApiOperation(value = "更新物资类别",notes = "更新物资类别信息")
    @PostMapping("/updateProductCategory")
    public Result updateProductCategory(@RequestBody ProductCategory productCategory){
        productCategoryService.updateProductCategory(productCategory);
        return Result.ok();
    }

    @PostMapping("/productCategoryDetail")
    @ApiOperation(value = "物资类别详情",notes = "物资类别详情")
    public Result productCategoryDetail(Long id){
        ProductCategory productCategory = productCategoryService.productCategoryDetail(id);
        return Result.ok().data("records",productCategory);
    }
}
